package com.zjd.service.impl;

import com.zjd.dao.UserDao;
import com.zjd.domain.User;
import com.zjd.service.UserService;
import com.zjd.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

public class UserServiceImpl implements UserService {
    @Override
    public void saveUser(User user) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.saveUser(user);
        MyBatisUtils.commitAndClose(sqlSession);
    }

    @Override
    public User login(User user) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        User loginUser = mapper.login(user);
        MyBatisUtils.commitAndClose(sqlSession);
        return loginUser;
    }

    @Override
    public void updateUser(User user) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserDao mapper = sqlSession.getMapper(UserDao.class);
        mapper.updateUser(user);
        MyBatisUtils.commitAndClose(sqlSession);
    }
}
